package com.yjhb.android.sbz.mvp.settinginfo;

import com.yjhb.android.sbz.App;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

/**
 * 创建者 zx
 * 创建时间 2020/11/24 12:40
 */
public class BindPhonePresenter extends ConventionPresenter<BindPhoneView> {
    private final String TAG = "BindPhonePresenter";

    public BindPhonePresenter(BindPhoneView bindPhoneView) {
        super(bindPhoneView);
    }

    @Override
    protected void onDestroy() {

    }


    /**
     * 发送验证码
     * @param tel
     */
    public void sendCode(String tel){
        if (checkUnLogin())return;
        if (view!=null){
            view.onWait();
        }
        HttpTool.request(model.bindingPhone(App.userInfo.getId(), tel), new HttpObserver<String>() {
            @Override
            public void onResult(String data) {
                if (view!=null){
                    view.onCodeSendSuccess();
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view!=null){
                    view.onFailure(code, msg);
                }
            }
        });
    }

    /**
     * 验证手机
     * @param tel
     * @param code
     */
    public void VerificationPhone(String tel,String code){
        if (checkUnLogin())return;
        if (view!=null){
            view.onWait();
        }
        HttpTool.request(model.checkPhoneBindingCode(App.userInfo.getId(), tel, code), new HttpObserver<String>() {
            @Override
            public void onResult(String data) {
                if (view!=null){
                    view.onBindSuccess();
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view!=null){
                    view.onFailure(code, msg);
                }
            }
        });
    }

}
